/**
 * Created by Administrator on 2019/06/06.
 */

fun main(args: Array<String>){

    var a = 1
    var b:Int? = 1
    var c:Long? = b?.toLong() ?: 0L

    var ar = Array(3){i -> (i* i).toString() }

    ar.forEach { println(it) }

    var intar : IntArray = intArrayOf(1,2,3)
    for (i in intar.indices){
        println("i = $i, value=" + intar[i])
    }

    val text = """
    |Tell me and I forget.
    |Teach me and I remember.
    |Involve me and I learn.
    |(Benjamin Franklin)
    """.trimMargin()
    println(text)

    var i = 10;
    println("i = $i")

    var s = "ABC"
    println("s.length =  ${s.length}")

    var dna = """${'$'}9.99""";
    println(dna)

    var x1 = 2
    var x2 = 5
    var max = if(x1 > x2) x1 else x2
    println(max)

    max = 0
    when(max){
        1,2,3,4,5-> println("get max value")
        else-> println("not get max value")
    }


    var av = 10;
    println("$a is in 1..10 ->${av in 1..10}")

    val listv = listOf<Int>(1,2,3,4,56)
    println("-1 is in index of listv ==> ${-1 in 0..listv.lastIndex}")

    listv.forEach { println(it) }

    var map = mapOf("a" to "ab", "b" to "bc", "c" to "cd")
    println("a" in map.keys)

    var notnull = listOf("a", "b", "c")
    print(notnull.firstOrNull()?:"null");

    for ((i, v) in notnull.withIndex())
    {
        println("index = $i and value = $v")
    }

    var ap = Apple()
    with(ap){
        clear()
        slice()
        eat()
    }
}

class Apple{
    fun clear() = println("clear apple")
    fun slice() = println("slice apple")
    fun eat() = println("eat apple")
}

fun String.goto3()
{
    println("Convert this to camelcase")
}